package com.gcl.rabbitmq;

import com.gcl.rabbitmq.utils.RabbitmqUtil;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Work01 {

    //  队列名称

    public static final String QUEUE_NAME = "Hello Word";

    public static void main(String[] args) throws IOException, TimeoutException {

        // 使用工具类获取信道
        Channel channel = RabbitmqUtil.getRabbitmqChannel();

        // 消息成功消费
        DeliverCallback deliverCallback = (consumerTag, delivery) -> {
            String msg = new String(delivery.getBody());
            System.out.println(msg);
        };

        // 消息被取消
        CancelCallback cancelCallback = (consumerTag)->{
            System.out.println(consumerTag + "消息消费被中断");
        };

        // 接搜消息
        System.out.println("W3等待接受消息。。。。。。");
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);
        System.out.println("W3等待接受消息。。。。。。");

    }
}
